<?php


namespace app\api\controller;

use app\data\Data;
use think\Request;

class Member extends Index
{
    /**
     * 显示资源列表
     * 首页，页面显示
     * @return \think\Response
     */
    public function index()
    {
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;

        $username = (isset($_GET['username']) && $_GET['username']) ? trim($_GET['username']) : null;

        $logmin = (isset($_GET['logmin']) && $_GET['logmin']) ? strtotime($_GET['logmin']) : 0;
        $logmax = (isset($_GET['logmax']) && $_GET['logmax']) ? (strtotime($_GET['logmax']) + 24 * 60 * 60 - 1) : time();

        $where['static'] = (isset($_GET['status']) && $_GET['status']) ? $_GET['status'] : array('neq', 0);
        $where['username|phone|email'] = array('like', "%$username%");
        $where['time'] = array(array('egt', $logmin), array('elt', $logmax), 'and');
        $where['role'] = 0;
		$where['status'] = 1;
		
        $zgh_member = new Data('user');
        $res['data'] = $zgh_member->selectPage($page, $where);
        $res['count'] = $zgh_member->count($where);
        if (isset($res) || !empty($res)) {
            $this->_jsonp('200', '会员列表数据获取成功', $res);
        } else {
            $this->_jsonp('1000', '会员列表数据获取失败', null);
        }
    }


    /**
     * 详情页
     */
    public function member_msg()
    {
        $where['uid'] = trim(input('get.uid'));
        $zgh_member = new Data('user');
        $res = $zgh_member->_find($where);
        if (isset($res) || !empty($res)) {
            $this->_jsonp('200', '查询成功', $res);
        } else {
            $this->_jsonp('1000', '查询失败', null);
        }
    }

    /**
     * 更改状态
     * 更改为启用
     */
    public function member_start()
    {
        $where['uid'] = trim(input('get.id'));
        $data['static'] = 1;
        $data['test'] = '';
		$where1['uid'] = $where['uid'];
		$data1['static'] = 1;
        if (isset($where) || !empty($where)) {
            $zgh_member = new Data('user');
            $zgh_member->_update($data, $where);
            action_log('会员列表修改状态', 'log_admin', 1);
			
			$zgh_member_info = new Data('shop_information');
            $zgh_member_info->_update($data1, $where1);
            $this->_jsonp('200', '操作成功', null);
        } else {
            action_log('会员列表修改状态', 'log_admin');
            $this->_jsonp('1000', '操作失败', null);
        }

    }

    /**
     * 更改状态
     * 更改为禁用
     */
    public function member_stop()
    {
        $where['uid'] = trim(input('get.id'));
        $data['static'] = 2;
        $data['test'] = trim(input('get.test'));
		
		$where1['uid'] = $where['uid'];
		$data1['static'] = 2;
        if (isset($where) || !empty($where)) {
            $zgh_member = new Data('user');
            $zgh_member->_update($data, $where);
            action_log('会员列表修改状态', 'log_admin', 1);
			
			
			$zgh_member_info = new Data('shop_information');
            $zgh_member_info->_update($data1, $where1);
            $this->_jsonp('200', '操作成功', null);
        } else {
            action_log('会员列表修改状态', 'log_admin');
            $this->_jsonp('1000', '操作失败', null);
        }
    }

}
